home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / TEST / GLUT / TEST7.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  4.2 KB  |  200 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <GL/glut.h>
  11.  
  12. int w1, w2;
  13.  
  14. void
  15. display(void)
  16. {
  17.   glClear(GL_COLOR_BUFFER_BIT);
  18. }
  19.  
  20. void
  21. time9(int value)
  22. {
  23.   if (value != 9) {
  24.     printf("FAIL: time9 expected 9\n");
  25.     exit(1);
  26.   }
  27.   printf("PASS: test7\n");
  28.   exit(0);
  29. }
  30.  
  31. void
  32. time8(int value)
  33. {
  34.   if (value != 8) {
  35.     printf("FAIL: time8 expected 8\n");
  36.     exit(1);
  37.   }
  38.   printf("window 1 to 350x250+20+200; window 2 to 50x150+50+50\n");
  39.   glutSetWindow(w1);
  40.   glutReshapeWindow(350, 250);
  41.   glutPositionWindow(20, 200);
  42.   glutSetWindow(w2);
  43.   glutReshapeWindow(50, 150);
  44.   glutPositionWindow(50, 50);
  45.   glutTimerFunc(1000, time9, 9);
  46. }
  47.  
  48. void
  49. time7(int value)
  50. {
  51.   if (value != 7) {
  52.     printf("FAIL: time7 expected 7\n");
  53.     exit(1);
  54.   }
  55.   printf("window 1 fullscreen; window 2 popped on top\n");
  56.   glutSetWindow(w1);
  57.   glutShowWindow();
  58.   glutFullScreen();
  59.   glutSetWindow(w2);
  60.   glutShowWindow();
  61.   glutPopWindow();
  62.   /* It can take a long time for glutFullScreen to really happen
  63.      on a Windows 95 PC.  I believe this has to do with the memory
  64.      overhead for resizing a huge soft color and/or ancillary buffers. */
  65.   glutTimerFunc(6000, time8, 8);
  66. }
  67.  
  68. void
  69. time6(int value)
  70. {
  71.   if (value != 6) {
  72.     printf("FAIL: time6 expected 6\n");
  73.     exit(1);
  74.   }
  75.   printf("change icon tile for both windows\n");
  76.   glutSetWindow(w1);
  77.   glutSetIconTitle("icon1");
  78.   glutSetWindow(w2);
  79.   glutSetIconTitle("icon2");
  80.   glutTimerFunc(1000, time7, 7);
  81. }
  82.  
  83. void
  84. time5(int value)
  85. {
  86.   if (value != 5) {
  87.     printf("FAIL: time5 expected 5\n");
  88.     exit(1);
  89.   }
  90.   glutSetWindow(w1);
  91.   if (glutGet(GLUT_WINDOW_X) != 20) {
  92.     printf("WARNING: x position expected to be 20\n");
  93.   }
  94.   if (glutGet(GLUT_WINDOW_Y) != 20) {
  95.     printf("WARNING: y position expected to be 20\n");
  96.   }
  97.   if (glutGet(GLUT_WINDOW_WIDTH) != 250) {
  98.     printf("WARNING: width expected to be 250\n");
  99.   }
  100.   if (glutGet(GLUT_WINDOW_HEIGHT) != 250) {
  101.     printf("WARNING: height expected to be 250\n");
  102.   }
  103.   glutSetWindow(w2);
  104.   if (glutGet(GLUT_WINDOW_X) != 250) {
  105.     printf("WARNING: x position expected to be 250\n");
  106.   }
  107.   if (glutGet(GLUT_WINDOW_Y) != 250) {
  108.     printf("WARNING: y position expected to be 250\n");
  109.   }
  110.   if (glutGet(GLUT_WINDOW_WIDTH) != 150) {
  111.     printf("WARNING: width expected to be 150\n");
  112.   }
  113.   if (glutGet(GLUT_WINDOW_HEIGHT) != 150) {
  114.     printf("WARNING: height expected to be 150\n");
  115.   }
  116.   printf("iconify both windows\n");
  117.   glutSetWindow(w1);
  118.   glutIconifyWindow();
  119.   glutSetWindow(w2);
  120.   glutIconifyWindow();
  121.   glutTimerFunc(1000, time6, 6);
  122. }
  123.  
  124. void
  125. time4(int value)
  126. {
  127.   if (value != 4) {
  128.     printf("FAIL: time4 expected 4\n");
  129.     exit(1);
  130.   }
  131.   printf("reshape and reposition window\n");
  132.   glutSetWindow(w1);
  133.   glutReshapeWindow(250, 250);
  134.   glutPositionWindow(20, 20);
  135.   glutSetWindow(w2);
  136.   glutReshapeWindow(150, 150);
  137.   glutPositionWindow(250, 250);
  138.   glutTimerFunc(1000, time5, 5);
  139. }
  140.  
  141. void
  142. time3(int value)
  143. {
  144.   if (value != 3) {
  145.     printf("FAIL: time3 expected 3\n");
  146.     exit(1);
  147.   }
  148.   printf("show both windows again\n");
  149.   glutSetWindow(w1);
  150.   glutShowWindow();
  151.   glutSetWindow(w2);
  152.   glutShowWindow();
  153.   glutTimerFunc(1000, time4, 4);
  154. }
  155.  
  156. void
  157. time2(int value)
  158. {
  159.   if (value != 2) {
  160.     printf("FAIL: time2 expected 2\n");
  161.     exit(1);
  162.   }
  163.   printf("hiding w1; iconify w2\n");
  164.   glutSetWindow(w1);
  165.   glutHideWindow();
  166.   glutSetWindow(w2);
  167.   glutIconifyWindow();
  168.   glutTimerFunc(1000, time3, 3);
  169. }
  170.  
  171. void
  172. time1(int value)
  173. {
  174.   if (value != 1) {
  175.     printf("FAIL: time1 expected 1\n");
  176.     exit(1);
  177.   }
  178.   printf("changing window titles\n");
  179.   glutSetWindow(w1);
  180.   glutSetWindowTitle("changed title");
  181.   glutSetWindow(w2);
  182.   glutSetWindowTitle("changed other title");
  183.   glutTimerFunc(2000, time2, 2);
  184. }
  185.  
  186. int
  187. main(int argc, char **argv)
  188. {
  189.   glutInitWindowPosition(20, 20);
  190.   glutInit(&argc, argv);
  191.   w1 = glutCreateWindow("test 1");
  192.   glutDisplayFunc(display);
  193.   glutInitWindowPosition(200, 200);
  194.   w2 = glutCreateWindow("test 2");
  195.   glutDisplayFunc(display);
  196.   glutTimerFunc(1000, time1, 1);
  197.   glutMainLoop();
  198.   return 0;             /* ANSI C requires main to return int. */
  199. }
  200.